package nz.co.doherty.gwtpbreadcrumbs.server.handler.reset;

import nz.co.doherty.gwtpbreadcrumbs.shared.entity.Customer;
import nz.co.doherty.gwtpbreadcrumbs.shared.entity.Product;
import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.reset.ResetDataAction;
import nz.co.doherty.gwtpbreadcrumbs.shared.rpc.reset.ResetDataResult;

import com.googlecode.objectify.Objectify;
import com.googlecode.objectify.ObjectifyService;
import com.philbeaudoin.gwtp.dispatch.server.ExecutionContext;
import com.philbeaudoin.gwtp.dispatch.server.actionHandler.ActionHandler;
import com.philbeaudoin.gwtp.dispatch.shared.ActionException;

public class ResetDataHandler implements
		ActionHandler<ResetDataAction, ResetDataResult> {

	
	@Override
	public ResetDataResult execute(ResetDataAction action,
			ExecutionContext context) throws ActionException {
		
		Objectify ofy = ObjectifyService.begin();
		ofy.delete(ofy.query(Product.class));
		ofy.delete(ofy.query(Customer.class));
		
		return new ResetDataResult();
		
	}

	@Override
	public void undo(ResetDataAction action, ResetDataResult result,
			ExecutionContext context) throws ActionException {
		// TODO Auto-generated method stub

	}

	@Override
	public Class<ResetDataAction> getActionType() {		
		return ResetDataAction.class;
	}

}
